//作业：随机生成100个文件，每个文件随机生成一个1到1000的数字，再取出最大值的那个文件
'use strict';
var fs = require('fs');
var arr = [];
var arr2 = [];
let solve={
    create:function(){
        var con = 5;
        while (con >= 1) {
            var str = 'file' + con;
            fs.writeFileSync('./' + str + '.txt', Math.ceil(Math.random() * 5).toString());
            var data = fs.readFileSync("./file" + con + ".txt");
            this.handle(data.toString(), 'file' + con);
            con--;
        }
    },
    handle:function(result, fileName){
        arr.push(Number(result));
        arr2.push(fileName);
    },
    result:function(){
        //console.log(Math.max(...arr));
        var index = arr.indexOf(Math.max(...arr))
        //console.log(index);
        // console.log(arr);
        // console.log(arr2);
        console.log('最大值的文件是' + arr2[index]);
    },
    init:function(){
        this.create();
        this.result();
    }
}
solve.init();



